package chapter07

/**
 * Created with IntelliJ IDEA.
 * ClassName: Test10_Tuple
 * Package: chapter07
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 *          Date: 2023-06-27
 *          Time: 21:58
 */

object Test10_Tuple {
  def main(args: Array[String]): Unit = {
    //元组 字面还以 元素的组合
    //创建 大小只有23 最多下标到22
    val tuple:(String,Int,Char,Boolean) = ("hello",100,'a',true)

    println(tuple)

    //访问数据
    println(tuple._1) //hello
    println(tuple._2) //100
    //通过索引获取值 从0开始
    println(tuple.productElement(1)) //100

    //遍历 迭代器
    for (elem <- tuple.productIterator){
      println(elem)
    }
    //元组和map是有关系的 "a" -> 12, "b" -> 23, "hello" -> 4 这底层就是一个二元组

    //嵌套
    val mul = (12,0.2,"hello",(123,"scala"),188)
    println(mul._4._2) //Scala


  }
}
